﻿using AutoMapper;
using BasicInformation.API.Application.Command.OutsourcingCommand;
using BasicInformation.Domain;
using BasicInformation.Infrastructure.Interface;
using MediatR;

namespace BasicInformation.API.Application.CommandHandler.OutsourcingCommandHandler
{
    public class OutsourcingCreateCommandHandler : IRequestHandler<OutsourcingCreateCommand, int>
    {
        private readonly IOutsourcingRepository outsourcingRepository;
        private readonly IMapper mapper;

        public OutsourcingCreateCommandHandler(IOutsourcingRepository outsourcingRepository, IMapper mapper)
        {
            this.outsourcingRepository = outsourcingRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(OutsourcingCreateCommand request, CancellationToken cancellationToken)
        {
            var info = mapper.Map<Outsourcing>(request);
            return await outsourcingRepository.Create(info);
        }
    }
}
